<template>
  <div class="borrow-container">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="book_id" label="书籍ID" align="center" width="100">
        <template slot-scope="scope"> {{ scope.row.book_id }} </template>
      </el-table-column>
      <el-table-column prop="name" label="书籍名称" align="center">
        <template slot-scope="scope"> {{ scope.row.name }} </template>
      </el-table-column>
      <el-table-column prop="borrow_date" label="借书时间" align="center">
        <template slot-scope="scope"> {{ scope.row.borrow_date }} </template>
      </el-table-column>
      <el-table-column prop="back_date" label="还书时间" align="center">
        <template slot-scope="scope"> {{ scope.row.back_date }} </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { findBorrowUser } from "@/api/borrow";
export default {
  data() {
    return {
      tableData: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
    async getData() {
      const id = +localStorage.getItem("id");
      const res = await findBorrowUser(id);

      const newRes = res.map((item) => {
        return {
          ...item,
          borrow_date: item.borrow_date.split("T")[0],
          back_date: item.back_date ? item.back_date.split("T")[0] : "未还书",
        };
      });

      this.tableData = newRes;
    },
  },
};
</script>

<style scoped>
.borrow-container {
  padding: 20px;
}
</style>